package com.chenglu.android.restaurant.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chenglu.android.R;
import com.chenglu.android.common.utils.GlideUtils;
import com.chenglu.android.common.utils.Utils;
import com.chenglu.android.goodsinfo.infoutils.GoodsInfoUtils;
import com.chenglu.android.index.bean.IndexRecomBean;
import com.chenglu.android.restaurant.bean.RestaurantSearchBean;

import java.util.List;

/**
 * c
 *
 * @author: lyj
 * @Created: by Copyright 2023/3/13 Guangzhou Hongma Technology Co., Ltd. All rights reserved.
 * @Description：商超和其他便利店的adapter数据
 */
public class SearchShopAdapter extends BaseQuickAdapter<RestaurantSearchBean.Data.Records, BaseViewHolder> {

    private Context mContext;

    public SearchShopAdapter(@Nullable Context context, List<RestaurantSearchBean.Data.Records> data) {
        super(R.layout.item_search_shop, data);
        this.mContext = context;

    }


    @Override
    protected void convert(@NonNull BaseViewHolder helper, RestaurantSearchBean.Data.Records item) {
        if (item == null) {
            return;
        }
        helper.addOnClickListener(R.id.rl_shop);
        helper.setText(R.id.tv_item_title, item.getShopsName());
        helper.setText(R.id.tv_item_score,Utils.formatZeroNumber(item.getScore())+"分");
        helper.setText(R.id.tv_item_sell,"销量 "+item.getMonthSaleCount());
        helper.setText(R.id.tv_item_distance,item.getDistance()+"km");
        String string = "";
        if(item.getDomainBusinessCategory().size()>0){
            for (int i = 0; i <item.getDomainBusinessCategory().size() ; i++) {
                string += item.getDomainBusinessCategory().get(i).getCategoryDesc()+"/";
            }
        }
        if(!TextUtils.isEmpty(string)){

            helper.setText(R.id.tv_item_des,string.substring(0,string.length()-1))
            .setVisible(R.id.tv_item_des,true);
        }else {
            helper.setVisible(R.id.tv_item_des,false);
        }

        ImageView imageView = helper.getView(R.id.iv_goods_img);
        GlideUtils.setImageView(mContext,item.getLogoImage(),imageView,8);

        //优惠卷的列表数据
        RecyclerView rvCoupon = helper.getView(R.id.item_rv_coupon);
        CouponListAdapter couponListAdapter = new CouponListAdapter(mContext,item.getCouponList());
        rvCoupon.setLayoutManager(new LinearLayoutManager(mContext));
        rvCoupon.setAdapter(couponListAdapter);

        //图片列表的数据
        if(item.getGoodsVOList().size()>0){
            helper.setVisible(R.id.item_rv_pic,true);
        }else {
            helper.setVisible(R.id.item_rv_pic,false);
        }
        RecyclerView rvPic = helper.getView(R.id.item_rv_pic);
        CenterItemPicAdapter itemPicAdapter = new CenterItemPicAdapter(mContext,item.getGoodsVOList());
        rvPic.setLayoutManager(new LinearLayoutManager(mContext,RecyclerView.HORIZONTAL,false));
        rvPic.setAdapter(itemPicAdapter);

        //跳转到 餐饮 商品详情页面
        itemPicAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {

                GoodsInfoUtils.goodsRestantInfo(mContext,itemPicAdapter.getData().get(position).getId(),itemPicAdapter.getData().get(position).getShopsTypeId());
//
            }
        });
    }


    private int thisPosition = 0;

    public int getThisPosition() {
        return thisPosition;
    }

    public void setThisPosition(int thisPosition) {
        this.thisPosition = thisPosition;
        notifyDataSetChanged();
    }
}
